﻿
using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Jocker;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace ManagoMes.Read.API.Applications.WangDefa
{
    public class processhtmlHandler : IRequestHandler<processhtmlCommond, ResultsDTO<processk>>
    {


        private readonly IBateRepository<processk> _Processk;

        

        public processhtmlHandler(IBateRepository<processk> processk)
        {
            _Processk = processk;
      
        }

        public async Task<ResultsDTO<processk>> Handle(processhtmlCommond request, CancellationToken cancellationToken)
        {

            try
            {
                var list = new ResultsDTO<processk>() { Code = 0 };

                var str = "select * from processk";
                var per = new processk();

                DapperHelper dapperHelper = new DapperHelper(); 
              var result = _Processk.GetAll(str, per, dapperHelper.MangoMesRead).ToList();

                if(!string.IsNullOrEmpty(request.ProcessName))
                {
                    result = result.Where(x => x.ProcessName == request.ProcessName).ToList();
                }
                if(!string.IsNullOrEmpty(request.ProcedureCode))
                {
                    result = result.Where(x => x.ProcedureCode == request.ProcedureCode).ToList();
                }
                if(request.isEnable>-1)
                {
                    result = result.Where(x =>  x.isEnable== request.isEnable).ToList();
                }
                list.Data = result;
                return list;

            }
            catch (Exception)
            {

                throw;
            }

         
        }
    }
}
